package enums;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.testng.annotations.Test;

public enum EnumWithCallBack {

    /**
     * 供给型回调
     */
    Spring(1, () -> 0),
    Summer(2, () -> 0.0f),
    Fail(3, () -> 9.99),
    WINTER(4, () -> 100L),

    /**
     * 转换型回调
     * 因为是枚举，转换规则是确定的，不允许传入转换规则
     */
    WEEK1(10, String::valueOf),
    WEEK2(11, i -> Integer.toString(i + 1)),



    ;

    private final int code;

    private Supplier<? extends Number> supplier;



    private Function<Integer, String> mapping;

    public int getCode() {
        return code;
    }

    public Supplier<? extends Number> getSupplier() {
        return supplier;
    }

    public Function<Integer, String> getMapping() {
        return mapping;
    }

    EnumWithCallBack(int code, Supplier<? extends Number> supplier) {
        this.code = code;
        this.supplier = supplier;
    }

    EnumWithCallBack(int code, Function<Integer, String> mapping) {
        this.code = code;
        this.mapping = mapping;
    }

}


